﻿using Microsoft.Extensions.DependencyInjection;

namespace MyWeb.Extensions.ServiceExtensions.Filter
{
    /// <summary>
    /// 请求拦截器 启动服务
    /// </summary>
    public static class FilterSetup
    {
        /// <summary>
        /// 请求拦截器 启动服务
        /// </summary>
        /// <param name="services"></param>
        /// <exception cref="ArgumentNullException"></exception>
        public static void AddFilterSetup(this IServiceCollection services)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));

            services.AddControllers(options =>
            {
                //全局注册请求拦截器
                options.Filters.Add(typeof(RequestLogFilterAttribute));
                options.Filters.Add(typeof(ResourceFilter));
                options.Filters.Add(typeof(AuthorizationFilter));
                options.Filters.Add(typeof(ExceptionExFilter));
                options.Filters.Add(typeof(ActionFilterAsync));
            });
        }
    }
}
